#include "QtOpenGlPlus.h"


QtOpenGlPlus::QtOpenGlPlus(QWidget *parent)
    : QGLWidget(parent)
{
  bInfoCarte = false ;
  bInfoGl = false ;
  QGLFormat formatu ;
  formatu.setDoubleBuffer(true) ;
  formatu.setRgba (true) ;
  formatu.setDepth (true) ;
  format().setDefaultFormat (formatu) ;
  makeCurrent () ;
  //nativeParentWidget()->setFocus () ;
  if (bInfoGl) {

  }

//    animationTimer.setSingleShot(true);
    connect(&animationTimer, SIGNAL(timeout()), this, SLOT(on_idle()));
    animationTimer.start(10);
}

QtOpenGlPlus::~QtOpenGlPlus() {

}

/**
  @brief Initialisation OpenGL
*/
void QtOpenGlPlus::initializeGL ()  {
  if (bInfoCarte) {
      std::cout << "GL_RENDERER   = " << glGetString(GL_RENDERER)   << std::endl;
      std::cout << "GL_VERSION    = " << glGetString(GL_VERSION)    << std::endl;
      std::cout << "GL_VENDOR     = " << glGetString(GL_VENDOR)     << std::endl;
      std::cout << "GL_EXTENSIONS = " << glGetString(GL_EXTENSIONS) << std::endl;
      std::cout << std::endl;
    }
   initGL () ;
}

/**
  @brief Affichage OpenGL
*/
void QtOpenGlPlus::paintGL ()  {
  callback_display() ;
}

/**
  @brief Redimension OpenGL
*/
void QtOpenGlPlus::resizeGL ( int width, int height ) {
  callback_reshape (width, height) ;
}

/**
  @brief Callback Initialisation OpenGL
*/
void QtOpenGlPlus::initGL() {

}

/**
  @brief Callback Affichage OpenGL
*/
void QtOpenGlPlus::callback_display() {
///////////////////////////////////////////////////
// Exemple For test Opengl //
///////////////////////////////////////////////////
// glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//   glClearColor(0.5, 0.5, 0.0, 1.0) ;
//   glColor3f(1.,0.,0.) ;
//   glBegin( GL_LINE_LOOP) ;
//     glVertex3f(0.,0.,0.) ;
//     glVertex3f(10.,0.,0.) ;
//     glVertex3f(10.,10.,0.) ;
//   glEnd() ;
}

/**
  @brief Callback Redimension OpenGL
  @param width : largeur de la vue
  @param height : hauteur de la vue
*/
void QtOpenGlPlus::callback_reshape(int width, int height) {
  Q_UNUSED(width) ;
  Q_UNUSED(height) ;
}

/**
  @brief Callback Boucle Inter d'affichage
*/
bool QtOpenGlPlus::callback_idle () {
  return true ;
}

void QtOpenGlPlus::on_idle() {
  bool bupdate = callback_idle() ;
  if (bupdate == true) {
    update() ;
  }
}

void QtOpenGlPlus::mousePressEvent ( QMouseEvent * event ) {
//   on_button_press_event (event, this) ;
  /*nativeParentWidget()->*/setFocus () ;
  Q_UNUSED(event)  ;
}

void QtOpenGlPlus::mouseMoveEvent ( QMouseEvent * event ) {
//   on_motion_notify_event(event, this) ;
  Q_UNUSED(event)  ;
}

void QtOpenGlPlus::mouseReleaseEvent ( QMouseEvent * event ) {
//   on_button_release_event(event, this) ;
  Q_UNUSED(event)  ;
}

void QtOpenGlPlus::wheelEvent ( QWheelEvent * event ) {
//   on_scroll_event(event, this) ;
  Q_UNUSED(event)  ;
}

void QtOpenGlPlus::keyPressEvent ( QKeyEvent * event ) {
//   on_key_press_event(event, this) ;
  Q_UNUSED(event)  ;
}

void QtOpenGlPlus::keyReleaseEvent ( QKeyEvent * event ) {
//   on_key_release_event(event, this) ;
  Q_UNUSED(event)  ;
}

void QtOpenGlPlus::closeEvent ( QCloseEvent * event ) {
//   on_close_event(event, this) ;
  Q_UNUSED(event)  ;
}
/*
bool QtOpenGlPlus::on_button_press_event(MouseEvent* event, InputWidget* scene) {
  Q_UNUSED(event)  ;
  Q_UNUSED(scene) ;
  return true ;
}

bool QtOpenGlPlus::on_motion_notify_event(MouseEvent* event, InputWidget* scene) {
  Q_UNUSED(event)  ;
  Q_UNUSED(scene) ;
  return true ;
}

bool QtOpenGlPlus::on_button_release_event(MouseEvent* event, InputWidget* scene) {
  Q_UNUSED(event)  ;
  Q_UNUSED(scene) ;
  return true ;
}

bool QtOpenGlPlus::on_scroll_event(EventScroll* event, InputWidget* scene) {
  Q_UNUSED(event)  ;
  Q_UNUSED(scene) ;
  return true ;
}

bool QtOpenGlPlus::on_key_press_event (KeyEvent* event, InputWidget* scene)  {
  Q_UNUSED(event)  ;
  Q_UNUSED(scene) ;
  return true ;
}

bool QtOpenGlPlus::on_key_release_event (KeyEvent* event, InputWidget* scene) {
  Q_UNUSED(event)  ;
  Q_UNUSED(scene) ;
  return true ;
}

bool QtOpenGlPlus::on_close_event (CloseEvent* event, InputWidget* scene) {
  Q_UNUSED(event)  ;
  Q_UNUSED(scene) ;
  return true ;
}
*/
